import React from 'react';
import {View, Text} from 'react-native';
import Crypto from '../utils/Crypto';
import CryptoJS from "crypto-js";

export default class CryptoDemo extends React.Component {

  state = {
    text: '123456'
  }

  componentDidMount () {
    const result = 'adfdsfdfdfsfsdfsdfdsfsdfdsffhghgh'
    const test = '31ae9c9252c0a0bd6e4413ec1361d7f83c3c8209b4695001bdd51459eaf291fe21';

    console.log('text AESencrypt', Crypto.AESencrypt(result))
    console.log('text AESdecrypt', Crypto.AESdecrypt(test))
    // console.log('CryptoJS',CryptoJS.enc.Utf8.parse("sgapp753214"));


  }

  //非utf-8
  render () {
    return (
      <View style={{flex: 1}}>
        <Text
          onPress={() => {
            const text = Crypto.AESencrypt(this.state.text);
            this.setState({
              text: text
            })
          }}
        > 加密</Text>
        <Text
          onPress={() => {
            const text = Crypto.AESdecrypt(this.state.text);
            this.setState({
              text: text
            })
          }}
        > 解密</Text>
        <Text selectable={true}>{this.state.text}</Text>
      </View>

    )
  }
}
